package com.jxbai.design.pattern.dcxy.prototype;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author jxbai
 * @date 2021/12/13 0013
 */
public class MyBatis {

    private final Map<String, User> cacheData = new ConcurrentHashMap<>();

    public User getUer(String name) throws CloneNotSupportedException {
        if (cacheData.containsKey(name)) {
            User user = cacheData.get(name);
            return (User) user.clone();
        } else {
            User user = new User(name, 18, null);
            cacheData.put(name, user);
            return (User) user.clone();
        }
    }
}
